﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web.Configuration;
using Harrby.Web.Configuration;
using Harrby.Web.Providers;
using Harrby.Web.Routing;

namespace Harrby.Web
{
    public static class HarrbyWebApplication
    {
        static HarrbyWebApplication()
        {
            HarrbyWebApplication.IsInitialized = false;
            HarrbyWebApplication.Initialize();
        }

        public static void Initialize()
        {
            ConfigurationSectionStorage configurationSectionDataStorage = (ConfigurationSectionStorage)ConfigurationManager.GetSection("harrby/dataStorage");
            HarrbyWebApplication.Settings = (HarrbyConfigurationSettings)ConfigurationManager.GetSection("harrby/settings");
            HarrbyWebApplication.Routings = (HarrbyRoutingCollection)ConfigurationManager.GetSection("harrby/routings");
            HarrbyWebApplication.Providers = new HarrbyProviderCollection();
            ProvidersHelper.InstantiateProviders(configurationSectionDataStorage.Providers, HarrbyWebApplication.Providers, typeof(HarrbyProvider));
            HarrbyWebApplication.Providers.SetReadOnly();
            HarrbyWebApplication.IsInitialized = true;
        }
        public static bool IsInitialized { get; private set; }
        public static HarrbyConfigurationSettings Settings { get; private set; }
        public static HarrbyProviderCollection Providers { get; private set; }
        public static HarrbyRoutingCollection Routings { get; private set; }
        public static HarrbyProvider Provider { get; private set; }
    }
}
